import json
from urllib import request

from django.http import JsonResponse, HttpResponse
from django.shortcuts import render
from .utils import *
from .utils import getCenterData,getPublicData,getCenterLeftData,getBottomLeftData,getCenterRightData,getCenterChangeDate,getBottomRightData


# Create your views here.
def center(request):

    if request.method=='GET':

        sumCar,highVolume,topCar,mostModel,mostBrand,averagePrice=getCenterData.getBaseData()
        lastSortList=getCenterData.getRollData()
        oilRate,eleRate,mixRate=getCenterData.getTypeRate()
        return JsonResponse({
            'sumCar':sumCar,
            "highVolume":highVolume,
            'topCar':topCar,
            'mostModel':mostModel,
            'mostBrand':mostBrand,

            'averagePrice':averagePrice,
            'lastSortList':lastSortList,
            'oilRate':oilRate,
            'eleRate':eleRate,
            'mixRate':mixRate,



        })


def centerLeft(request):
    if request.method=='GET':

        lastPieList=getCenterLeftData.getPieBrandData()
        return JsonResponse({

            'lastPieList':lastPieList,
        })



def bottomLeft(request):
    if request.method=='GET':

        brandlist,pricelist,volumelist=getBottomLeftData.get_square_data()
        return JsonResponse({
            'brandlist':brandlist,
            'pricelist':pricelist,
            'volumelist':volumelist,

            # 'lastPieList':lastPieList,
        })



def centerRight(request):
    if request.method=='GET':
        realData=getCenterRightData.getPriceSortData()


        return JsonResponse({
            'realData':realData

            # 'lastPieList':lastPieList,
        })


def centerRightChange(request,energyType):
    if request.method=='GET':
        oil_data, electric_data,other_data=getCenterChangeDate.getCenterChangeDate()
        realData=[]
        if request.method == 'GET':
            oil_data, electric_data, other_data = getCenterChangeDate.getCenterChangeDate()
            real_data = []

            if energyType == '0':
                real_data = electric_data

            elif energyType == '1':
                real_data = oil_data
            else:
                real_data = other_data

        return JsonResponse({
                'realData': real_data
            })



def bottomRight(request):
    if request.method=='GET':
        carData=getBottomRightData.get_car_data()



        return JsonResponse({
            'carData':carData

        })



